<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>消息通知</title>
    <link rel="stylesheet" href="css/amazeui.min.css" />
    <link rel="stylesheet" href="css/app.css" />
    <link rel="stylesheet" href="css/swiper-3.3.1.min.css" />
    <script src="js/amazeui.min.js" type="text/javascript"></script>
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="css/pageCode.css">
    <style>
        body {
            max-width: 640px;
            margin: 0 auto;
            font-size: 10px;
            background: #F2F3F8;
        }

        * {
            box-sizing: border-box;
        }

        [class*=am-u-] {
            padding: 0;
        }
    </style>
</head>

<body>
    <!--头部-->
    <header class="am-u">
        <div class="am-u-sm-12 head_nav" style="margin:0;">
            <div class="am-u-sm-2 am-vertical-align" style="text-align: center;">
                <a href="message.html">
                    <img src="img/return@2x.png" class="am-vertical-align-middle" alt="" />
                </a>
            </div>
            <div class="am-u-sm-8 head_text">
                消息通知
            </div>
            <div class="am-u-sm-2" style="color: #fff;font-size: 13px;text-align: center;">

            </div>
        </div>
    </header>
    <div style="clear: both;"></div>
    <div class="am-u" id='xx_list'>

    </div>
    <div style="clear: both;"></div>
    <div class="tcdPageCode" style="color: red;text-align: center;"></div>
    <script src="js/jquery-1.11.3.js"></script>
    <script src="js/jquery.page.js"></script>
    <script src="js/loading.js"></script>
    <script>
        var token1 = sessionStorage.getItem("token");
        var you = GetQueryString("mid");

        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
        //          第几页
        var p1 = 1;
        //          每页几条数据
        var pagesize1 = 8;
        $.ajax({
            type: 'POST',
            url: "http://www.rice.com/app/api/h5_access",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            datatype: "JSON",
            data: {
                method: "get_msg_list",
                token: token1,
                type: you,
                p: p1,
                pagesize: pagesize1
            },
            success: function (data) {
                var data1 = JSON.parse(data);
                console.log(data1);
                if (data1.status === 1) {
                    var html = "";
                    for (var i in data1.data.list) {
                        html += '<a href="messagedetails.html?id=' + data1.data.list[i].msg_id +
                            '"><div class="am-u-sm-12" style="border-bottom: 1px solid #BCBEBD;background: #fff;"><div class="am-u-sm-2" style="text-align: center;padding: 15px 0 15px 0;"><img src="img/messageTip.png" width="25" alt="" /></div>';
                        html +=
                            '<div class="am-u-sm-10"><span style="color:#fff;font-size: 16px;color: #424242;padding-left:10px; padding-top: 3px;">' +
                            data1.data.list[i].title + '</span>';
                        html +=
                            '<span class="am-sm-text-right am-fr" style="display: block;font-size: 13px;padding-top: 3px;padding-right: 5px;color: #BABABA;">' +
                            data1.data.list[i].add_time + '</span>';
                        html +=
                            '<span style="padding-left: 10px;display: block;font-size: 13px;padding-top: 3px;color: #BABABA;">' +
                            data1.data.list[i].content + '</span></div></div></a>';
                    }
                    if (html == "") {
                        $("#xx_list").html(
                            "<div style='width:60%;margin:20px 20%;clear:both;'><img src='img/roun.png' style='width:100%;'></div>"
                        );
                        $(".tcdPageCode").css("display", "none");
                    } else {
                        $("#xx_list").html(html);
                    }
                    var r = data1.data.total;
                    r = Math.ceil(r / pagesize1);
                    $(".tcdPageCode").createPage({
                        pageCount: r,
                        current: 1,
                        backFn: function (pagesize1) {}
                    });
                } else if (Number(data1.status) == 2) {
                    alert(data1.message);
                    window.location.href = "login.html";
                } else {
                    alert(data1.message);
                }
            }
        });
        $(".tcdPageCode").on("click", 'a', function () {
            var h = $(this).html();
            if (h == "下一页") {
                var t = $('.tcdPageCode  span.current').html();
                t = parseInt(t);
                p1 = t + 1;
            } else if (h == "上一页") {
                var t = $('.tcdPageCode  span.current').html();
                t = parseInt(t);
                p1 = t - 1;
            } else {
                h = parseInt(h);
                p1 = h;
            }
            $.ajax({
                type: 'POST',
                url: "http://www.rice.com/app/api/h5_access",
                contentType: "application/x-www-form-urlencoded; charset=utf-8",
                datatype: "JSON",
                data: {
                    method: "get_msg_list",
                    token: token1,
                    type: you,
                    p: p1,
                    pagesize: pagesize1
                },
                success: function (data) {
                    var data1 = JSON.parse(data);
                    console.log(data1);
                    if (data1.status === 1) {
                        var html = "";
                        for (var i in data1.data.list) {
                            html += '<a href="messagedetails.html?id=' + data1.data.list[i].msg_id +
                                '"><div class="am-u-sm-12" style="border-bottom: 1px solid #BCBEBD;background: #fff;"><div class="am-u-sm-2" style="text-align: center;padding: 15px 0 15px 0;"><img src="img/messageTip.png" width="25" alt="" /></div>';
                            html +=
                                '<div class="am-u-sm-10"><span style="color:#fff;font-size: 16px;color: #424242;padding-left:10px; padding-top: 3px;">' +
                                data1.data.list[i].title + '</span>';
                            html +=
                                '<span class="am-sm-text-right am-fr" style="display: block;font-size: 13px;padding-top: 3px;padding-right: 5px;color: #BABABA;">' +
                                data1.data.list[i].add_time + '</span>';
                            html +=
                                '<span style="padding-left: 10px;display: block;font-size: 13px;padding-top: 3px;color: #BABABA;">' +
                                data1.data.list[i].content + '</span></div></div></a>';
                        }
                        $("#xx_list").html(html);
                        var r = data1.data.total;
                        r = Math.ceil(r / pagesize1);
                        $(".tcdPageCode").createPage({
                            pageCount: r,
                            current: p1,
                            backFn: function (pagesize1) {}
                        });
                    } else if (Number(data1.status) == 2) {
                        alert(data1.message);
                        window.location.href = "login.html";
                    } else {
                        alert(data1.message);
                    }
                }
            });
        })
    </script>
</body>

</html>